package org.csu.agrisupply.api.controller.front;

import org.csu.agrisupply.api.common.CommonResponse;
import org.csu.agrisupply.api.entity.Item;
import org.csu.agrisupply.api.service.ItemService;
import org.csu.agrisupply.api.service.RCService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/items/")
public class ItemController {
    @Autowired
    private ItemService itemService;
    @GetMapping("")
    @ResponseBody
    //得到所有商品
    public CommonResponse<List<Item>> getItemList(){
        return itemService.getItemList();
    };
    @GetMapping("{itemId}")
    @ResponseBody
    //得到单个商品
    public CommonResponse<Item> getItem(@PathVariable("itemId") String itemid){
        return itemService.getItem(itemid);
    };
    @PostMapping("RC/{rcId}")
    @ResponseBody
    //上架供应商品
    CommonResponse<Item> RCputonItem(@PathVariable("rcId")String rcId,
                                     @RequestBody Item item){
        return itemService.RCputonItem(rcId,item);
    };
    @PutMapping("{itemId}/RC/{rcId}")
    @ResponseBody
    //修改供应商品的信息
    public CommonResponse<Item> RCupdateItem(@PathVariable("itemId") String itemid, @PathVariable("rcId")String rcId,
                                             @RequestBody Item item){
        return itemService.RCupdateItem(itemid,rcId,item);
    };
    //下架供应商品
    @DeleteMapping("{itemId}/RC/{rcId}")
    @ResponseBody
    CommonResponse<Item> RCputoffItem(@PathVariable("itemId") String itemid, @PathVariable("rcId")String rcId){
        return itemService.RCputoffItem(itemid,rcId);
    };
    //得到对应RCId的所有item
    @GetMapping("RC/{rcId}")
    @ResponseBody
    CommonResponse<List<Item>> getRCitems(@PathVariable("rcId")String rcId){
        return itemService.getRCitems(rcId);
    };
}
